var screenWidth = $(window).width();
var screenHeight = $(window).height();
var lotteryData = [];
var params = { //line_no so_no prom_code params.staffNum
  staffNum: '',
  drawCode: 0, //抽奖code
  line_no: '',
  prom_code: '',
  so_no: '',
  province: "", //省
  city: "", //市
  area: "", //区
  recordAddress: ""
};

function _onorientationchange(e) {
  if (window.orientation == 90 || window.orientation == -90) {
    $("#landscape_wrap").css("display", "-webkit-box"); //显示竖屏浏览提示框
    document.getElementById('viewport').content = 'width=750,user-scalable=no,target-densitydpi=' +
      (750 / parseInt(window.screen.width) * window.devicePixelRatio * 160);
  } else {
    //竖屏下恢复默认显示效果
    setTimeout(function () {
      location.reload();
    }, 50)
    $("#landscape_wrap").css("display", "none");
    document.getElementById('viewport').content = 'width=750,user-scalable=no,target-densitydpi=' +
      (750 / parseInt(window.screen.width) * window.devicePixelRatio * 160);
  }
  _resize(e);
};

var cfg = {
  isBegin: false, // 是否在游戏中
  num: 0, // 抽奖机会
  getPrize: ""
};

var prize = [{
    id: 0,
    productCode: 0,
    name: "享优乐空气净化器",
    img: "images/haze_prize_1.png",
    lc: "台",
    awards: "一等奖"
  },
  {
    id: 1,
    productCode: 1,
    name: "享优乐净水器",
    img: "images/haze_prize_2.png",
    lc: "台",
    awards: "二等奖"
  },
  {
    id: 2,
    productCode: 2,
    name: "HEPA滤网",
    img: "images/haze_prize_3.png",
    lc: "盒",
    awards: "三等奖"
  },
  {
    id: 3,
    productCode: 3,
    name: "气味滤网",
    img: "images/haze_prize_4.png",
    lc: "盒",
    awards: "四等奖"
  },
  {
    id: 4,
    productCode: 4,
    name: "密集修护精华体验装",
    img: "images/haze_prize_5.png",
    lc: "套",
    awards: "五等奖"
  }
];

var productCodeObj = {
  "1809003-01": 0, //享优乐空气净化器 一等奖  1809003-01
  "1809003-02": 1, //享优乐净水器 二等奖  1809003-02
  "20202331": 2, //HEPA滤网 三等奖 20202331 
  "20202332": 3, //气味滤网 四等奖 20202332  
  "20203848": 4 //密集修护精华体验装 五等奖 20203848  
};
var prizeObj = {
  "1809003-01": '享优乐空气净化器1台',
  "1809003-02": '享优乐净水器1台',
  "20202331": 'HEPA滤网1盒',
  "20202332": '气味滤网1盒',
  "20203848": '密集修护精华体验装1套',
};
var d = new Date();
$(function () {
  // 'use strict'; // 严格模式
  var ua = navigator.userAgent.toLowerCase();
  //如果不是微信浏览器
  // if(ua.match(/MicroMessenger/i) !="micromessenger") {
  //   $("#landscape_wrap_wx").css("display", "-webkit-box");  //显示竖屏浏览提示框
  // }else{
  //   if(ua.indexOf("/zh_cn") == -1){
  //     $("#landscape_wrap_mobile").css("display", "-webkit-box");  //显示竖屏浏览提示框
  //   }
  // }

  if (window.orientation == 90 || window.orientation == -90) {
    $("#landscape_wrap").css("display", "-webkit-box"); //显示竖屏浏览提示框
    document.getElementById('viewport').content = 'width=750,user-scalable=no,target-densitydpi=' +
      (750 / parseInt(window.screen.width) * window.devicePixelRatio * 160);
  }

  window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", function (e) {
    _onorientationchange(e);
  }, false);

  var utils = {
    getQueryString: function (name) {
      var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'),
        r = window.location.search.substr(1).match(reg);
      return (r != null) ? unescape(r[2]) : null;
    },

    getPureUrl: function () {
      var currLink = window.location.href;
      return currLink.substr(0, currLink.lastIndexOf('/') + 1);
    },

    hideItem: function (el, speed, callback) {
      var style = 'display:block;opacity:0;-webkit-transition:all ' + speed / 1000 + 's;';
      el.attr('style', style);
      setTimeout(function () {
        el.attr('style', 'display:none;');
        callback && callback();
      }, speed);
      return this;
    },

    showItem: function (el, speed, callback) {
      var style = 'display:block;opacity:0.01;';
      el.attr('style', style);
      setTimeout(function () {
        el.attr('style', 'display:block;opacity:1;' +
          '-webkit-transition:all ' + (speed - 100) / 1000 + 's;');
      }, 100);
      setTimeout(function () {
        callback && callback();
      }, speed);
      return this;
    },

    buildImgListStr: function (listElSel) {
      var listEls = $(listElSel).find('img'),
        listArr = [];
      // alert(listEls);
      for (var i = listEls.length; i-- > 0;) {
        listArr.push(listEls.eq(i).data('src'));
      }
      return listArr;
    }

  };
  //加载图片
  // function ImageLoader(imgList,doneCbk,progressCbk) {
  //   var list;
  //   list = imgList;
  //   var downImg = 0,
  //         percent = 0,
  //         length  = list.length;
  //     for (var i = length; i-- > 0;) {
  //       var curImg = new Image();
  //       curImg.src = list[i];
  //       curImg.onload = function() {
  //         downImg++;
  //         percent = Math.floor((downImg / length) * 100);
  //         progressCbk && progressCbk(percent);
  //         if (percent == 100 && doneCbk) {
  //           doneCbk();
  //           return ;
  //         }
  //       }
  //     }
  // };
  function ImageLoader(imgList) {
    this.list = imgList;
  };
  ImageLoader.prototype = {
    progress: function (doneCbk, progressCbk) {
      var downImg = 0,
        percent = 0,
        length = this.list.length;
      for (var i = length; i-- > 0;) {
        var curImg = new Image();
        curImg.src = this.list[i];
        curImg.onload = function () {
          downImg++;
          percent = Math.floor((downImg / length) * 100);
          progressCbk && progressCbk(percent);
          if (percent == 100 && doneCbk) {
            doneCbk();
            return this;
          }
        }
      }
    }
  };


  // 三级联动
  // function setProvince() { // 省
  //   $("#province").val("000001|广东省").html('<option value="" selected>请选择省</option>');
  //   $("#city").html('<option value="" selected>请选择市</option>');
  //   $("#county").html('<option value="" selected>请选择区</option>');
  //   $("#area").html('<option value="" selected>请选择县</option>');
  //   //设置省选项
  //   $.ajax({  //http://activity-test.infinitus.com.cn/dev_nx_nx_47ab184e-22e3-b38254bc/http/tranGateWayEsbGet.do?url=front%2Fapi%2Fgbss%2Fpo%2Faddress%2Fpoarea%3FparentAreaCode%3D000000%26areaType%3D1
  //     headers:{ 'X-Requested-With': 'XMLHttpRequest' },
  //     url : system.urls + 'http/tranGateWayEsbGet.do?url=front%2Fapi%2Fgbss%2Fpo%2Faddress%2Fpoarea%3FparentAreaCode%3D000000%26areaType%3D1',
  //     // dataType: 'json',
  //     success: function(data,status,xhr){
  //       // console.log( typeof(data))
  //       var data_infor =JSON.parse(data);
  //       var datas=data_infor.result;
  //       if(datas){
  //         for (var i = 0; i < datas.length; i ++) {
  //           $("<option></option>").val(datas[i].areaCode+"|"+datas[i].areaDesc).text( datas[i].areaDesc).appendTo($("#province"));
  //         }
  //         if(params.recordAddress != ""){
  //           var recordAddress = params.recordAddress.split("aa");
  //           $("#province").val(recordAddress[0]);
  //           $("#province-key").val(recordAddress[0].split("|")[1]);
  //         }
  //       }
  //     }
  //   })

  //   $("#province").on("change", function() {
  //     var proCode=$("#province").val().split("|")[0];
  //     $("#city").prev("input").val("");
  //     $("#county").prev("input").val("");
  //     $("#area").prev("input").val("");
  //     setCity(proCode);
  //   });

  //   $("#city").on("change", function() {
  //     var cityCode=$("#city").val().split("|")[0];
  //     $("#county").prev("input").val("");
  //     $("#area").prev("input").val("");
  //     setArea(cityCode);
  //   });
  //   $("#county").on("change", function() {
  //     var countyCode=$("#county").val().split("|")[0];
  //     $("#area").prev("input").val("");
  //     setSmallArea(countyCode);
  //   });
  // }

  // 市
  // function setCity(proCode) {
  //   $("#city").html('<option value="" selected>请选择市</option>');
  //   $("#county").html('<option value="" selected>请选择区</option>');
  //   $("#area").html('<option value="" selected>请选择县</option>');
  //   $("#city, #county").val("");
  //   $("#city, #county").parent().prev("input").val("");
  //   // if (previous != "") {
  //     //设置市选项
  //     $.ajax({ 
  //       url : system.urls + 'http/tranGateWayEsbGet.do?url=front%2Fapi%2Fgbss%2Fpo%2Faddress%2Fpoarea%3FparentAreaCode%3D'+proCode+'%26areaType%3D2',
  //     // url : system.urls + 'http/tranGateWayEsbGet.do?url=front%2Fapi%2Fgbss%2Fpo%2Faddress%2Fpoarea%3FparentAreaCode%3D000000%26areaType%3D2',
  //       dataType: 'json',
  //       success: function(data,status,xhr){
  //         // console.log( typeof(data))
  //         // var data_infor =JSON.parse(data);
  //         var datas=data.result;
  //         if(datas){
  //           for (var i = 0; i < datas.length; i ++) {
  //             var option = "<option value='" + datas[i].areaCode + "|" +datas[i].areaDesc+ "'>" + datas[i].areaDesc + "</option>";
  //             $("#city").append(option);
  //           }
  //         }
  //       }
  //     })
  //   // }
  // }

  // 区
  // function setArea(cityCode) {
  //   $("#county").html('<option value="" selected>请选择区</option>');
  //   $("#area").html('<option value="" selected>请选择县</option>');
  //   $("#county").val("");
  //   $("#county").parent().prev("input").val("");
  //   // if (city != "") {
  //     //设置县/区选项
  //     $.ajax({
  //       url : system.urls + 'http/tranGateWayEsbGet.do?url=front%2Fapi%2Fgbss%2Fpo%2Faddress%2Fpoarea%3FparentAreaCode%3D'+cityCode+'%26areaType%3D3',
  //       dataType: 'json',
  //       success: function(data,status,xhr){
  //         var datas=data.result;
  //         if(datas){
  //           for (var i = 0; i < datas.length; i ++) {
  //             var option = "<option value='" + datas[i].areaCode + "|"+ datas[i].areaDesc + "'>" + datas[i].areaDesc + "</option>";
  //             $("#county").append(option);
  //           }
  //         }
  //       }
  //     })
  //   // }
  // }
  // 县
  // function setSmallArea(countyCode) {
  //   $("#area").html('<option value="" selected>请选择县</option>');
  //   $("#area").val("");
  //   $("#area").parent().prev("input").val("");

  //   // if (city != "") {
  //     //设置县/区选项
  //     $.ajax({
  //       url : system.urls + 'http/tranGateWayEsbGet.do?url=front%2Fapi%2Fgbss%2Fpo%2Faddress%2Fpoarea%3FparentAreaCode%3D'+countyCode+'%26areaType%3D4',
  //       dataType: 'json',
  //       success: function(data,status,xhr){
  //         var datas=data.result;
  //         if(datas){
  //           for (var i = 0; i < datas.length; i ++) {
  //             var option = "<option value='" + datas[i].areaCode + "|"+ datas[i].areaDesc + "'>" + datas[i].areaDesc + "</option>";
  //             $("#area").append(option);
  //           }
  //         }
  //       }
  //     })
  //   // }
  // }

  // 显示搜索弹窗
  function showSearch() {
    if ($(".pop").is(":visible")) {
      $(".pop-box").css({
        display: "none"
      });
      $(".search-shop").css({
        display: "inline-block"
      });
    } else {
      $(".search-shop").css({
        display: "inline-block"
      });
      utils.showItem($(".pop"), 500);
    }
  }

  function pop_addr() {
    $(".save_addr").on("click", function () {
      var proArea = $("#province").val().split("|")[1],
        cityArea = $("#city").val().split("|")[1],
        countyArea = $("#county").val().split("|")[1],
        smallArea = $("#area").val().split("|")[1];
      if (typeof (proArea) == 'undefined') {
        showErroTips("请选择省份~");
        return false;
      } else if (typeof (cityArea) == 'undefined') {
        showErroTips("请选择城市~");
        return false;
      } else if (typeof (countyArea) == 'undefined') {
        showErroTips("请选择区~");
        return false;
      } else if (typeof (smallArea) == 'undefined') {
        showErroTips("请选择县~");
        return false;
      }
      var address_infor = proArea + cityArea + countyArea + smallArea;
      $(".choose_area").css({
        color: "#111111"
      });
      $(".choose_area").html(address_infor);
      $(".search-shop").css({
        display: "none"
      });
      utils.hideItem($(".pop_addr"), 500, function () {});
    });
  }
  // pop
  function pop() {
    // 有奖品
    $(".get-prize .confirm2").on("click", function () {
      showSearch();
    });

    // rule
    $(".rule-btn").on("click", function () {
      if (!cfg.isBegin) {
        $(".rule-btn").addClass("active");
        setTimeout(function () {
          utils.showItem($(".pop"), 400);
          $(".rule").css({
            display: "inline-block"
          });
        }, 100);
        setTimeout(function () {
          $(".rule-btn").removeClass("active");
        }, 300);
      }
    });

    // prize-btn
    $(".prize-btn").on("click", function () {
      // createPrizeTemplate(params.staffNum);
      // if (!cfg.isBegin) {
      //   $(".prize-btn").addClass("active");
      //   setTimeout(function () {
      //     utils.showItem($(".pop"), 400);
      //     $(".price").css({
      //       display: "inline-block"
      //     });
      //   }, 100);
      //   setTimeout(function () {
      //     $(".prize-btn").removeClass("active");
      //   }, 300);
      // }
      location.href = "./history.html"
    });

    // my-prize-btn 查看我的奖品
    $(".my-prize-btn").on("click", function () {
      createPrizeTemplate(params.staffNum)
      if (!cfg.isBegin) {
        $(".price").css({
          display: "inline-block"
        });
        utils.showItem($(".pop"), 500);
      }
    });

    // choose_area 选择地址页面
    $(".choose_area").on("click", function () {
      $(".choose_area_show").css({
        display: "none"
      });
      if (!cfg.isBegin) {
        utils.showItem($(".pop_addr"), 500);
        $(".search-shop").css({
          display: "inline-block"
        });
      }
    });

    // my-address 填写配送地址 设置一个全局变量保存识别id
    $(".my-address").on("click", function () {
      // $(".my-address").css({"backgroundColor": "#4fbba4","color":"#ffffff"});
      setTimeout(function () {
        $(".get-prize").css({
          display: "none"
        });
      }, 250);
      setTimeout(function () {
        // $(".my-address").css({"backgroundColor": "","color":""});
        $(".shopping-address").css({
          display: "inline-block"
        });
      }, 700);

      // utils.showItem($(".pop"), 700);
    });
    // my-prize 查看我的奖品
    $(".my-prize").on("click", function () {
      createPrizeTemplate(params.staffNum);
      $(".my-prize").css({
        "backgroundColor": "#4fbba4",
        "color": "#ffffff"
      });
      setTimeout(function () {
        $(".get-prize").css({
          display: "none"
        });
      }, 250)
      setTimeout(function () {
        $(".my-prize").css({
          "backgroundColor": "",
          "color": ""
        });
        $(".price").css({
          display: "inline-block"
        });
      }, 700)
    });

    // share-myfriend 图片分享给小伙伴
    $(".share-myfriend").on("click", function () {
      $(".share-myfriend").css({
        "backgroundColor": "#4fbba4",
        "color": "#ffffff"
      });
      setTimeout(function () {
        $(".show_img").fadeIn(1000);
      }, 250)
      setTimeout(function () {
        $(".share-myfriend").css({
          "backgroundColor": "",
          "color": ""
        });
      }, 500)
      setTimeout(function () {
        setShareImg();
      }, 1200)
    });
    //go-back
    $(".go-back").on("click", function () {
      $(".go-back").css({
        "backgroundColor": "#4fbba4",
        "color": "#ffffff"
      });
      setTimeout(function () {
        $(".show_img").fadeOut(1000);
      }, 250)
      setTimeout(function () {
        $(".go-back").css({
          "backgroundColor": "",
          "color": ""
        });
      }, 500)
    });

    $(".close").on("click", function () {
      utils.hideItem($(".pop"), 500, function () {
        $(".rule").css({
          display: "none"
        });
        $(".price").css({
          display: "none"
        });
        $(".shopping-address").css({
          display: "none"
        });
        $(".get-prize").css({
          display: "none"
        });
      });
    });

    //收货人输框正在输入时
    $(".consignee").on('input', function () {
      if (!($('.consignee').val() == '')) {
        $(".clear_con").show();
      } else {
        $(".clear_con").hide();
      }
    })

    //电话号码输框正在输入时
    $(".tel").on('input', function () {
      if (!($('.tel').val() == '')) {
        $(".clear_tel").show();
      } else {
        $(".clear_tel").hide();
      }
    })

    //身份证号码输框正在输入时
    $(".idnumber").on('input', function () {
      if (!($('.idnumber').val() == '')) {
        $(".clear_id").show();
      } else {
        $(".clear_id").hide();
      }
    })

    //地址输框正在输入时
    $(".address_detail").on('input', function () {
      if (!($('.address_detail').val() == '')) {
        $(".clear_addr").show();
      } else {
        $(".clear_addr").hide();
      }
    })

    //清空收货人
    $(".clear_con").on("click", function () {
      $(".consignee").val("");
      setTimeout(function () {
        $(".clear_con").hide();
      }, 200)
    });
    //清空电话号码
    $(".clear_tel").on("click", function () {
      $(".tel").val('');
      setTimeout(function () {
        $(".clear_tel").hide();
      }, 200)
    });
    //清空身份证号码
    $(".clear_id").on("click", function () {
      $(".idnumber").val('');
      setTimeout(function () {
        $(".clear_id").hide();
      }, 200)
    });
    //清空地址
    $(".clear_addr").on("click", function () {
      $(".address_detail").val('');
      setTimeout(function () {
        $(".clear_addr").hide();
      }, 200)
    });

    //提交地址
    $(".submit_addr").on("click", function () {
      var str = /^[1][3,4,5,6,7,8][0-9]{9}$/;
      var strid = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
      var consignee = $(".consignee").val();
      var tel = $(".tel").val();
      var address_detail = $(".choose_area").text() + $(".address_detail").val();
      var idnumber = $(".idnumber").val();
      //传一,二等奖lineno promcode
      var promCode = $(".my-address").data("promcode") || $(".aP1811200 .sign-now").data("promcodel") || $(".aP1812200 .sign-now").data("promcodel");
      var lineNo = $(".my-address").data("lineno") || $(".aP1811200 .sign-now").data("linenol") || $(".aP1812200 .sign-now").data("linenol");
      var subproArea = $("#province").val().split("|")[1],
        subcityArea = $("#city").val().split("|")[1],
        subcountyArea = $("#county").val().split("|")[1],
        subsmallArea = $("#area").val().split("|")[1];
      var emojiCheck = consignee + $(".address_detail").val();

      if ($(".consignee").val() == "") {
        showErroTips("请输入收货人~");
        return false;
      }
      if (!str.test($(".tel").val())) {
        showErroTips("请输入正确的手机号码~")
        return false;
      }
      if (!strid.test($(".idnumber").val())) {
        showErroTips("请输入正确的身份证号码~")
        return false;
      }
      if (typeof (subproArea) == 'undefined' || typeof (subcityArea) == 'undefined' || typeof (subcountyArea) == 'undefined' || typeof (subsmallArea) == 'undefined') {
        showErroTips("请选择所在区域~");
        return false;
      }
      if ($(".address_detail").val() == "") {
        showErroTips("请输入详细地址~");
        return false;
      }
      // 判断是否有输入表情符
      isEmojiCharacter(emojiCheck, function () {
        submitAddr(consignee, tel, address_detail, idnumber, promCode, lineNo)
      });

    });

    //跳转到登录页面
    $(".game_login").on("click", function () {
      $(".game_login").addClass("active");
      setTimeout(function () {
        window.location.href = system.memberLogin;
      }, 200);
      setTimeout(function () {
        $(".game_login").removeClass("active");
      }, 300);
    });

    //判断正确的手机号码和身份证号码
    $(".tel").on("blur", function () {
      // setThemePage("blur");
      checkPhoneNum($(".tel").val())
    });
    $(".idnumber").on("blur", function () {
      // setThemePage("blur");
      checkIDNum($(".idnumber").val())
    });

  }
  //提交用户收货地址
  function submitAddr(consignee, tel, address_detail, idnumber, promCode, lineNo) {
    var receiverName = encodeURI(encodeURI(consignee));
    var receiverAddress = encodeURI(encodeURI(address_detail));
    $.ajax({
      headers: {
        'X-Requested-With': 'XMLHttpRequest'
      },
      url: system.urls + 'http/tranGateWayPost.do?url=front%2Fydapi%2Fdealer%2Fskg%2F' + params.staffNum + '%2Fawards%2Fdelivery&jsonStr=%7B%22promCode%22%3A%22' + promCode + '%22%2C%22dealerNo%22%3A%22' + params.staffNum + '%22%2C%22receiverName%22%3A%22' + consignee + '%22%2C%22lineNo%22%3A%22' + lineNo + '%22%2C%22receiverAddress%22%3A%22' + address_detail + '%22%2C%22receiverPhone%22%3A%22' + tel + '%22%2C%22receiverId%22%3A%22' + idnumber + '%22%7D',
      type: 'get',
      success: function (data) {
        $(".submit_addr").css({
          "backgroundColor": "#64cbb5",
          "color": "#ffffff"
        });
        setTimeout(function () {
          $(".choose_area_show").css({
            display: "block"
          });
          showErroTips("提交成功 ~");
        }, 250)
        setTimeout(function () {
          utils.hideItem($(".pop"), 500, function () {
            $(".submit_addr").css({
              "backgroundColor": "",
              "color": ""
            });
            $(".shopping-address").css({
              display: "none"
            });
          });
        }, 500)
      }

    })
  }
  // judge 判断是否中奖
  function judge(result) {
    for (var i = 0; i < result.length; i++) {
      var p = result[0];
      if (result[i] == p) {
        if (i == result.length - 1) {
          var prizeIndex = result[0];
          // 中奖奖品
          cfg.getPrize = prize[prizeIndex];
          if (prize[p].awards == '一等奖' || prize[p].awards == '二等奖') {
            $(".get-prize .btn-wrap .my-address").css("display", 'block');
            //传一,二等奖识别码
            // $(".my-address").data("prizeid", prize[p].id);
            // $(".my-address").data("line_no", prize[p].id);
          } else {
            $(".get-prize .btn-wrap .my-address").css("display", 'none');
          }

          $(".get-prize").addClass("active");
          //中奖页面图片
          $(".get-prize-title img").attr("src", prize[p].img);
          //分享页面图片
          $(".wrapper_img .share_good_image").attr("src", prize[p].img);
          //中奖页面文字
          $(".get-prize-title .what-awards,.wrapper_img .what-awards").html(prize[p].awards);
          $(".get-prize-title .prize-good-name,.wrapper_img .prize-good-name").html(prize[p].name);
          $(".get-prize-title b,.wrapper_img b").html(prize[p].lc);

          $(".no-record").hide();
          $(".no-prize").hide();
          $(".get_prize").show();

          //获取和创建奖品列表
          createPrizeTemplate(prize[p]);
        }
      } else {
        console.log("无中奖");
        break;
      }
    }
  }

  // 获取和创建奖品列表
  function createPrizeTemplate(infor) {
    $(".price .get_prize").html('');
    $.ajax({
      headers: {
        'X-Requested-With': 'XMLHttpRequest'
      },
      url: system.urls + 'http/tranGateWayGet.do?url=%2Ffront%2Fydapi%2Fdealer%2Fskg%2Fawards%3FpromCode%3DP1811200%2CP1812200%26dealerNo%3D' + params.staffNum + '&t=' + d.getTime(),
      type: 'GET',
      success: function (datas) {
        var data = JSON.parse(datas)
        try {
          if (data) {
            for (var k = 0; k < data.length; k++) {
              if (data[k].prize_code == '') {
                data.splice(k, 1);
              }
            }
            if (data.length > 0) {
              $(".no-prize").hide();
            } else {
              $(".no-prize").show();
              return;
            }
            var $div = "";
            for (var i = 0; i < data.length; i++) {
              $div += '<div class="price-good ">';
              $div += '<div class="price-good-infor">';
              if (data[i].prize_code == '1809003-01') {
                $div += '<div class="good-img haze-good-img0"></div>';
                $div += '<div class="good-detail">';
                $div += '<div class="whatprice">一等奖</div>';
                $div += '<p class="good-name">享优乐空气净化器1台</p>';
              } else if (data[i].prize_code == '1809003-02') {
                $div += '<div class="good-img haze-good-img1"></div>';
                $div += '<div class="good-detail">';
                $div += '<div class="whatprice">二等奖</div>';
                $div += '<p class="good-name">享优乐净水器1台</p>';
              } else if (data[i].prize_code == '20202331') {
                $div += '<div class="good-img haze-good-img2"></div>';
                $div += '<div class="good-detail">';
                $div += '<div class="whatprice">三等奖</div>';
                $div += '<p class="good-name">HEPA滤网1盒</p>';
              } else if (data[i].prize_code == '20202332') {
                $div += '<div class="good-img haze-good-img3"></div>';
                $div += '<div class="good-detail">';
                $div += '<div class="whatprice">四等奖</div>';
                $div += '<p class="good-name">气味滤网1盒</p>';
              } else {
                $div += '<div class="good-img haze-good-img4"></div>';
                $div += '<div class="good-detail">';
                $div += '<div class="whatprice">五等奖</div>';
                $div += '<p class="good-name">密集修护精华体验装1套</p>';
              }
              $div += '</div>';
              $div += '</div>';
              $div += '<div class="price-addr a' + data[i].prom_code + '">';
              if (data[i].prize_code == "1809003-01" || data[i].prize_code == "1809003-02") {
                if (data[i].receiver_address == null || data[i].receiver_address == '') {
                  $div += '<p><span>配送地址:</span><span>(空)</span></p>'; //promcode lineno
                  $div += '<div class="sign-now" data-promcodel=' + data[i].prom_code + ' ' + 'data-linenol=' + data[i].line_no + '>马上填写</div>';
                } else {
                  $div += '<p><span>配送地址:</span><span>' + data[i].receiver_address + '</span></p>';
                }
              } else {
                if (data[i].receiver_address == null || data[i].receiver_address == '') {
                  $div += '<p><span>提货地址:</span><span> (正在更新，请稍候)</span></p>';
                } else {
                  $div += '<p><span>提货地址:</span><span>' + data[i].receiver_address + '</span></p>';
                }
              }
              $div += '</div>';
              if (data[i].status == Number('9')) {
                $div += '<div class="overdue-box">';
                $div += '<div class="overdue-bg"></div>	';
                $div += '<div class="overdue">已失效</div>';
                $div += '</div>';
              }
              $div += '</div>';
            };
            $(".price .get_prize").append($div);
            // sign-now 填写配送地址
            $(".sign-now").on("click", function () {
              $(".price").css({
                display: "none"
              });
              setTimeout(function () {
                $(".shopping-address").css({
                  display: "inline-block"
                });
              }, 500);

              utils.showItem($(".pop"), 700);
            });

            //一等奖分享图片
            $(".haze-good-img0").on("click", function () {
              $(".wrapper_img .share_good_image").attr("src", "images/haze_prize_1.png");
              $(".wrapper_img .what-awards").html("一等奖");
              $(".wrapper_img .prize-good-name").html("享优乐空气净化器");
              $(".wrapper_img b").html("台");
              setTimeout(function () {
                $(".show_img").fadeIn(1000);
              }, 250)
              setTimeout(function () {
                setShareImg();
              }, 1200)
            });
            //二等奖分享图片
            $(".haze-good-img1").on("click", function () {
              $(".wrapper_img .share_good_image").attr("src", "images/haze_prize_2.png");
              $(".wrapper_img .what-awards").html("二等奖");
              $(".wrapper_img .prize-good-name").html("享优乐净水器");
              $(".wrapper_img b").html("台");
              setTimeout(function () {
                $(".show_img").fadeIn(1000);
              }, 250)
              setTimeout(function () {
                setShareImg();
              }, 1200)
            });
            //三等奖分享图片//三等奖分享图片
            $(".haze-good-img2").on("click", function () {
              $(".wrapper_img .share_good_image").attr("src", "images/haze_prize_3.png");
              $(".wrapper_img .what-awards").html("三等奖");
              $(".wrapper_img .prize-good-name").html("HEPA滤网");
              $(".wrapper_img b").html("盒");
              setTimeout(function () {
                $(".show_img").fadeIn(1000);
              }, 250)
              setTimeout(function () {
                setShareImg();
              }, 1200)
            });
            //四等奖分享图片
            $(".haze-good-img3").on("click", function () {
              $(".wrapper_img .share_good_image").attr("src", "images/haze_prize_4.png");
              $(".wrapper_img .what-awards").html("四等奖");
              $(".wrapper_img .prize-good-name").html("气味滤网");
              $(".wrapper_img b").html("盒");
              setTimeout(function () {
                $(".show_img").fadeIn(1000);
              }, 250)
              setTimeout(function () {
                setShareImg();
              }, 1200)
            });
            //五等奖分享图片
            $(".haze-good-img4").on("click", function () {
              $(".wrapper_img .share_good_image").attr("src", "images/haze_prize_5.png");
              $(".wrapper_img .what-awards").html("五等奖");
              $(".wrapper_img .prize-good-name").html("密集修护精华体验装");
              $(".wrapper_img b").html("套");
              setTimeout(function () {
                $(".show_img").fadeIn(1000);
              }, 250)
              setTimeout(function () {
                setShareImg();
              }, 1200)
            });
          } else {

          }
        } catch (error) {
          console.log(error)
        }
      }
    })
  };
  //一等奖分享图片
  $(".haze-good-img0").on("click", function () {
    $(".wrapper_img .share_good_image").attr("src", "images/haze_prize_1.png");
    $(".wrapper_img .what-awards").html("一等奖");
    $(".wrapper_img .prize-good-name").html("享优乐空气净化器");
    $(".wrapper_img b").html("台");
    setTimeout(function () {
      $(".show_img").fadeIn(1000);
    }, 250)
    setTimeout(function () {
      setShareImg();
    }, 1200)
  });
  //二等奖分享图片
  $(".haze-good-img1").on("click", function () {
    $(".wrapper_img .share_good_image").attr("src", "images/haze_prize_2.png");
    $(".wrapper_img .what-awards").html("二等奖");
    $(".wrapper_img .prize-good-name").html("享优乐净水器");
    $(".wrapper_img b").html("台");
    setTimeout(function () {
      $(".show_img").fadeIn(1000);
    }, 250)
    setTimeout(function () {
      setShareImg();
    }, 1200)
  });
  //三等奖分享图片//三等奖分享图片
  $(".haze-good-img2").on("click", function () {
    $(".wrapper_img .share_good_image").attr("src", "images/haze_prize_3.png");
    $(".wrapper_img .what-awards").html("三等奖");
    $(".wrapper_img .prize-good-name").html("HEPA滤网");
    $(".wrapper_img b").html("盒");
    setTimeout(function () {
      $(".show_img").fadeIn(1000);
    }, 250)
    setTimeout(function () {
      setShareImg();
    }, 1200)
  });
  //四等奖分享图片
  $(".haze-good-img2").on("click", function () {
    $(".wrapper_img .share_good_image").attr("src", "images/haze_prize_4.png");
    $(".wrapper_img .what-awards").html("四等奖");
    $(".wrapper_img .prize-good-name").html("气味滤网");
    $(".wrapper_img b").html("盒");
    setTimeout(function () {
      $(".show_img").fadeIn(1000);
    }, 250)
    setTimeout(function () {
      setShareImg();
    }, 1200)
  });
  //五等奖分享图片
  $(".haze-good-img4").on("click", function () {
    $(".wrapper_img .share_good_image").attr("src", "images/haze_prize_5.png");
    $(".wrapper_img .what-awards").html("五等奖");
    $(".wrapper_img .prize-good-name").html("密集修护精华体验装");
    $(".wrapper_img b").html("套");
    setTimeout(function () {
      $(".show_img").fadeIn(1000);
    }, 250)
    setTimeout(function () {
      setShareImg();
    }, 1200)
  });

  // sign-now 填写配送地址
  $(".sign-now").on("click", function () {
    $(".price").css({
      display: "none"
    });
    setTimeout(function () {
      $(".shopping-address").css({
        display: "inline-block"
      });
    }, 500);

    utils.showItem($(".pop"), 700);
  });

  $("#lottery #click").click(function () {
    // if (click == false) {
    //     click = true;
    //     alertLayer();
    // }
    alertLayer();
  });


  //登录相关操作
  function alertLayer() {

    if (common.deploycolId !== localStorage.getItem("deploycolId")) {
      localStorage.removeItem("isLogin");
    }

    var isLogin = localStorage.getItem("isLogin") ? JSON.parse(localStorage.getItem("isLogin")) : {
      login: 0,
      staffNum: ""
    };
    if (isLogin.login == 0) { //未登陆
      login(1);
    } else { //已登录
      console.log("loginIn");
      startDraw();
    }
  }


  function login(type) {
    layer.open({
      type: 3,
      title: [
        '登录您的账号',
        'background-color:#58a0ea; color:#fff; text-align:center;'
      ],
      className: 'login-popuo',
      content: '<div class="pwd"><input class="staffNum" name="staffNum" type="tel" placeholder="请输入您的卡号" /></div><div class="pwd"><input class="password" name="password" type="password" placeholder="请输入您的密码" /></div><p class="error"></p><div class="button" data-type=' +
        type + '>登录</div>',
      style: 'width:6rem;background-color:#fff; color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
      shadeClose: false
    });
  }


  function loading(isOpen) {
    $('.loading-bar')[isOpen ? 'removeClass' : 'addClass']('hidden');
  }

  function trim(str) { //删除左右两端的空格
    return str.replace(/(^\s*)|(\s*$)/g, "");
  }


  $('#container').on("click touchstart", ".login-popuo .button", function (e) {
    var current = $(e.currentTarget);
    var container = current.closest('.login-popuo');
    var inputVal1 = trim(container.find(".staffNum").val()),
      inputVal2 = trim(container.find(".password").val());
    var type = current.attr('data-type');
    var t = +new Date();
    var urlSplit = window.location.href.split("/");
    if (inputVal1 != "" && inputVal2 != "") {
      $.ajax({
        type: "post",
        url: common.url + "/sys/login",
        dataType: "json",
        data: {
          dealerNo: inputVal1,
          password: hex_md5(inputVal2)
        },
        beforeSend: function () {
          loading(1);
        },
        complete: function () {
          loading();
        },
        success: function (data) {
          if (data && data.code === 40006) {
            common.staffNum = inputVal1;
            localStorage.setItem("isLogin", JSON.stringify({
              login: 1,
              staffNum: common.staffNum
            })); //保存登录信息

            localStorage.setItem("deploycolId", common.deploycolId);

          }
          if (type == 2) {
            location.href = './history.html';
            return;
          }
          if (data && (data.code === 40005 || data.code === 40006)) {
            layer.open({
              type: 3,
              title: '温馨提示',
              className: 'againNotice',
              content: '<div class="notice">' + (data.code === 40005 ?
                  '抽奖活动尚未开始，敬请期待！' : '抽奖活动已结束，感谢关注！') +
                '</div><div class="button">确定</div>',
              style: 'width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
              shadeClose: false,
              end: function () {
                click = false;
              }
            });
            $(".againNotice  .button").on("click", function () {
              layer.closeAll();
            })
          }
          layer.closeAll();
          common.staffNum = inputVal1;
          localStorage.setItem("isLogin", JSON.stringify({
              login: 1,
              staffNum: common.staffNum
          })); //保存登录信息
          localStorage.setItem("deploycolId", common.deploycolId);
          if (type == 1) { // 点击抽奖登录 成功后直接抽奖
              console.log("errorIn");
              // startDraw();
          } else { // 点击 中奖纪录登录  成功后跳转
              location.href = './history.html';
          }
        },
        error: function (data) {
          if (data.status == 400) {
            // 1为点击抽奖时  登录   2为点击查看历史登录
            if (type == 1 && data.responseText == '您已抽过奖') {
              layer.open({
                type: 3,
                title: [
                  '温馨提示',
                  'background-color:#58a0ea; color:#fff; text-align:center;'
                ],
                className: 'againNotice',
                content: '<div class="zjnotice">您已经抽过奖了，不能重复抽奖，谢谢！</div><div class="button">确定</div>',
                style: 'width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                shadeClose: false,
                end: function () {
                  location.href = common.skipUrl;
                }
              });
            } else {
              container.find('.error').addClass('red').text('*卡号或密码不正确，请重新输入');
            }
            $(".againNotice  .button").on("click", function () {
              layer.closeAll();
            })
          } else if (data.status == 200) {
            layer.closeAll();
            common.staffNum = inputVal1;
            localStorage.setItem("isLogin", JSON.stringify({
              login: 1,
              staffNum: common.staffNum
            })); //保存登录信息
            localStorage.setItem("deploycolId", common.deploycolId);
            if (type == 1) { // 点击抽奖登录 成功后直接抽奖
              console.log("errorIn");
              // startDraw();
            } else { // 点击 中奖纪录登录  成功后跳转
              location.href = './history.html';
            }
          }
        }
      })

    } else {
      container.find('.error').addClass('red').text('*' + (!inputVal1 ? '卡号' : '密码') + '不能为空');
    }
  })

  // startGame
  function startGame() {
    var u = 155,
      l = prize.length;
    $('.game-btn').click(function () {

      if (common.deploycolId !== localStorage.getItem("deploycolId")) {
        localStorage.removeItem("isLogin");
      }

      var isLogin = localStorage.getItem("isLogin") ? JSON.parse(localStorage.getItem("isLogin")) : {
        login: 0,
        staffNum: ""
      };

      if (isLogin.login == 0) { //未登陆
        login(1);
        return;
      }




      // 判断是否在转盘和抽奖次数是否大于0
      var isBegin = cfg.isBegin;
      if (false) {
        return false;
      } else {
        cfg.isBegin = true;
        cfg.num--;
        $(".game-btn-tips .chance").html(cfg.num);
        $(".game-btn").addClass("active");
        setTimeout(function () {
          $(".game-btn").removeClass("active");
          if (cfg.num == 0) $(".game-btn").addClass("off");
        }, 500);

        //传一,二等奖lineno promcode
        // $(".my-address").data("lineno", params.line_no);
        // $(".my-address").data("promcode", params.prom_code);
        // $(".hand").hide();
        $(".game li").css('backgroundPositionY', 0);

        // num_arr = [1, 2, 3];
        // judge(num_arr);


         //  抽奖结果 
         $.ajax({ 
            headers:{ 'X-Requested-With': 'XMLHttpRequest' },
            url: common.url + "/lottery/act?dealerNo=" + JSON.parse(localStorage.getItem("isLogin")).staffNum,
            type: 'GET',
            success: function (data) {
              var num_arr = [];   //抽奖结果随机数
              // console.log(typeof (parseInt(data)))
              try {
                if (data.code === 40005 || data.code === 40006) {
                  lottery.stopAndInit();
                  layer.open({
                      type: 3,
                      title: '温馨提示',
                      className: 'againNotice',
                      content: '<div class="notice">' + (data.code === 40005 ?
                              '抽奖活动尚未开始，敬请期待！' : '抽奖活动已结束，感谢关注！') +
                          '</div><div class="button">确定</div>',
                      style: 'width:6rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                      shadeClose: false,
                      end: function () {
                          click = false;
                      }
                  });
                  $(".againNotice  .button").on("click", function () {
                      layer.closeAll();
                  })
              }
              if (data.code == 40002) {
                  layer.open({
                      type: 3,
                      title: '温馨提示',
                      className: 'errortNotice',
                      content: '<div class="notice">卡号未登录，请稍后再试！</div><div class="button">确定</div>',
                      style: 'width:6rem; background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                      shadeClose: false,
                  });
                  $(".errortNotice  .button").on("click", function () {
                      location.reload();
                  })
              } else if (data.code == 0) {

                localStorage.setItem("qualiSeqNo", data.content.qualiSeqNo);

                num_arr = [common.prize[data.content.awardsCode]["position"] ,common.prize[data.content.awardsCode]["position"] ,common.prize[data.content.awardsCode]["position"]];
                // judge(num_arr);
                $(".game li").each(function (index) {
                  var _num = $(this);
                  setTimeout(function () {
                    _num.animate({
                      backgroundPositionY: (u * 60) - (u * num_arr[index])
                    },
                     {
                      duration: 6000 + index * 3000,
                      easing: "easeInOutCirc",
                      complete: function () {
                        // if (index == 2) {
                        //   cfg.isBegin = false;
                        //   $(".pop-box").css({display: "none"});
                        //   $(".pop-box.active").css({display: "inline-block"}).removeClass("active");
                        //   // oSwiper.unlockSwipes();
                        //   if (!$(".pop").is(":visible")) {
                        //     utils.showItem($(".pop"), 500);
                        //   }
                        // }
                      }
                    });
                  }, index * 100);
                });


                var msg = ""

                if (common["prize"][data.content.awardsCode].status == "1") {
                    msg = "恭喜您获得<b>" + common["prize"][data.content.awardsCode]["title"] + "</b>!<br/>请填写收货地址，公司将在2周内配送，请确保信息正确并保持电话畅通，谢谢！";
                } else if (common["prize"][data.content.awardsCode].status == "2") {
                    msg = "恭喜您获得<b>" + common["prize"][data.content.awardsCode]["title"] + "</b>!<br/>公司将在2周内电话与您联系领奖事宜，请保持电话畅通，谢谢！";
                } else if (common["prize"][data.content.awardsCode].status == "0") {
                    msg = "恭喜您获得<b>" + common["prize"][data.content.awardsCode]["title"] + "</b>!<br/>公司将在2周内发放，后期可登录纷享荟“我的”进行查询，谢谢！";
                } else if (common["prize"][data.content.awardsCode].status == "4") {
                    msg = "很遗憾未中奖，感谢您的参与！"
                }

                setTimeout(function () {
                    layer.open({
                        title: '温馨提示',
                        className: 'drawNotice',
                        content: '<div class="zjnotice">' + msg + '</div><div class="button">' + (common["prize"][data.content.awardsCode].status == "1" ?
                            '<a style="text-decoration: none; color: inherit;" href="./address.html' + '?qualiSeqNo=' + localStorage.getItem("qualiSeqNo") + '">' + '点此填写收货地址</a>' :
                            '返回直播') + '</div>',
                        style: 'width:6rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;font-size:18px',
                        shadeClose: false,
                        end: function () {
                            if (!(lottery.data.status == 1)) {
                                location.href = common.skipUrl;
                            }
                        }
                    });
                    $(".drawNotice  .button").on("click", function () {
                        layer.closeAll();
                    })
                }, 6000)

              } else if (data.code == 40007) { //超过次数
                  layer.open({
                      type: 3,
                      title: [
                          '温馨提示',
                          'background-color:#58a0ea; color:#fff; text-align:center;'
                      ],
                      className: 'startNotice',
                      content: '<div class="zjnotice">' + '您抽奖已超过指定次数' +
                          '</div><div class="button">' + (
                              '<a style="text-decoration: none; color: inherit;" href="./history.html">查看中奖记录</a>'
                          ) + '</div>',
                      style: 'width:6rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                      shadeClose: false,
                      end: function () {
                          // location.href = common.skipUrl;
                      }
                  });
                  $(".startNotice  .button").on("click", function () {
                      layer.closeAll();
                  })
              } else if (data.code == 40008) { //没有抽奖资格
                  layer.open({
                      type: 3,
                      title: [
                          '温馨提示',
                          'background-color:#58a0ea; color:#fff; text-align:center;'
                      ],
                      className: 'startNotice',
                      content: '<div class="zjnotice">你已没有抽奖资格</div><div class="button">返回直播</div>',
                      style: 'width:6rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                      shadeClose: false,
                      end: function () {
                          location.href = common.skipUrl;
                      }
                  });
                  $(".startNotice  .button").on("click", function () {
                      layer.closeAll();
                  })
              }

              } catch (error) {
                console.log(error)
              }
            },
            error:function (errordatas) {
              cfg.isBegin = false;
              showErroTips(errordatas.responseText);
              return false;
            }
         })



      }
    });
  };



  // 初始化游戏
  function initGame() {
    // 显示规则页面
    // utils.showItem($(".pop"), 400);
    $(".rule").css({
      display: "inline-block"
    });
    var wxcode = system.wechatAuthorizeCode;
    getLotteryNumber(2);
    // $.ajax({  
    //   headers:{ 'X-Requested-With': 'XMLHttpRequest' },
    //   url: system.urls +'login/getOpenIdAndDealerNoByCode/'+wxcode+'.do',
    //   type: 'GET',
    //   success: function (data, status, xhr) {
    //     var t,y,m,r,time;
    //     t = xhr.getResponseHeader('Date');
    //     time=new Date(xhr.getResponseHeader("Date"));
    //     y = time.getFullYear();
    //     m=time.getMonth();
    //     r=time.getDate();
    //     // 正式
    //     if (y>=2019 && m>=0 && r>=16) {
    //       // 隐藏规则页面
    //       utils.hideItem($(".pop"), 400);
    //       $(".rule").css({display: "none"});
    //       // 显示结束页面
    //       $(".index").hide();
    //       $(".active_over").show()
    //     } else{
    //       // 显示规则页面
    //       // utils.showItem($(".pop"), 400);
    //       // $(".rule").css({display: "inline-block"});
    //     }
    //     try {
    //       if (typeof (parseInt(data)) === 'number') {
    //         $(".game_login").css({"display": "none"});
    //         $(".game-btn").css({"display": "block"});
    //         params.staffNum=data
    //         //获取抽奖次数
    //         getLotteryNumber(data);
    //         // createPrizeTemplate();
    //       } else {
    //         $(".game-btn").css({"display": "none"});
    //         $(".game_login").css({"display": "block"});
    //       }
    //     } catch (error) {
    //       console.log(error)
    //     }
    //   },
    //   error: function(XmlHttpRequest,textStatus,errorThrown){  
    //     $(".no-prize").css({display: "block"});
    //     $(".game-btn-tips .chance").html('0');
    //     $("#loading").remove();
    //     $(".game-btn").css({"display": "none"});
    //     $(".game_login").css({"display": "block"});
    //   }, 
    // })
    $(".game-btn").css({
      "display": "block"
    });
    pop_addr();
    pop();
    // setProvince();
    setQrCode();
  }

  //获取用户抽奖次数
  function getLotteryNumber(staffNum) {
    startGame();
    // $.ajax({  
    //   headers:{ 'X-Requested-With': 'XMLHttpRequest' },
    //   url: system.urls +'http/tranGateWayGet.do?url=front%2Fydapi%2Fdealer%2Fskg%2F'+staffNum+'%2Fdraw-dealer-quali%3FpromCode%3DP1811200,P1812200&t='+d.getTime(),
    //   type: 'GET',
    //   // dataType: 'json',
    //   success: function (datas) {
    //     var data=JSON.parse(datas)
    //     try {
    //       if (data) {
    //         cfg.num=data.length;
    //         lotteryData=data;
    //         utils.hideItem($("#loading"), 1000, function() {
    //           $("#loading").remove();
    //           if (cfg.num > 0) {  //line_no so_no prom_code
    //             params.line_no = lotteryData[0].line_no;
    //             params.so_no = lotteryData[0].so_no;
    //             params.prom_code = lotteryData[0].prom_code;
    //             //开始游戏
    //             startGame();
    //           }
    //         });
    //         // 初始化抽奖次数
    //         $(".game-btn-tips .chance").html(cfg.num);
    //         if (cfg.num == 0){
    //           $(".game-btn").addClass("off");
    //         }
    //       } else {

    //       }
    //     } catch (error) {
    //       console.log(error)
    //     }
    //   }
    // })
  }

  // start ---------------------------------------------------------
  new ImageLoader(utils.buildImgListStr($("#preload-list"))).progress(function () {
    //获取中奖人名单和获得的奖品
    // $.ajax({
    //   headers:{ 'X-Requested-With': 'XMLHttpRequest' },
    //   url: system.urls +'lottery/top10.do?t='+d.getTime(),
    //   type: 'GET',
    //   success:function (data) {
    //     var datas=JSON.parse(data);
    //     var newData = [],        
    //           sta = {},           
    //           prizeNum = "";
    //           // dataObj = [];
    //     if(datas.length > 0){       //若有数据滚动显示
    //       for(var i=0;i<datas.length;i++){
    //         prizeNum = prizeObj[datas[i].awardsId];
    //         sta = {
    //           name : datas[i].name,
    //           title : prizeNum
    //         }
    //         newData.push(sta);
    //         sta = {};
    //       }
    //       var $li = "";
    //       for(var i = 0; i <newData.length; i++){
    //         $li +='<li><span class="get_prize_name">'+newData[i].name+'&nbsp;&nbsp;获得&nbsp;&nbsp;</span><span class="get_prize_good_name">'+newData[i].title+',</span></li>';
    //       };
    //       $(".winners-list #scrollList").append($li);
    //       var liallw=0;
    //       var ali=$(".winners-list #scrollList li");
    //       for (var j = 0; j < ali.length; j++) {
    //         liallw +=parseInt(ali[j].offsetWidth);
    //       }
    //       $(".winners-list #scrollList li").width();
    //       //设置ul的宽
    //       $('.winners-list #scrollList').width(liallw+340);
    //       setInterval(showImg,2000*ali.length);
    //       showImg();
    //       function showImg () {
    //         $('#scrollList').animate({'margin-left':-(liallw-310)},2000*ali.length,'linear',function () {
    //           // showImg()
    //           $('#scrollList').css('margin-left',0);
    //         });
    //       }	
    //     }else{        //若无抽奖数据
    //       $("#scrollList").html("<li style='font-size:26px;line-height:52px; color: #794809;'>活动即将开始~</li>")
    //     }
    //   },
    //   error: function(XmlHttpRequest,textStatus,errorThrown){  
    //     $("#scrollList").html("<li style='font-size:26px;line-height:52px; color: #794809;'>活动即将开始~</li>")
    //   }, 
    // })
    initGame();
  }, function (pct) {
    // alert(pct);
    $(".loader-in").css({
      width: pct + "%"
    });
    $("#loading .percent span").html(pct);
  });

  // ImageLoader(utils.buildImgListStr($("#preload-list")),function () {
  //   share()
  //   initGame();
  // },function (pct) {
  //   $(".loader-in").css({width: pct + "%"});
  //   $("#loading .percent span").html(pct);
  // });

});

// 显示错误提示
function showErroTips(text) {
  $(".erro_tips").html(text);
  $(".erro_tips").show();
  setTimeout(function () {
    $(".erro_tips").hide();
  }, 3000);
};

// 判断身份证号码
function checkIDNum(iDNumber, cbk) {
  var str = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
  if (!str.test(iDNumber)) {
    showErroTips("请输入正确的身份证号码")
    return false;
  } else {
    cbk && cbk();
  }
};
// 判断手机号码
function checkPhoneNum(phoneNumber, cbk) {
  var str = /^[1][3,4,5,6,7,8][0-9]{9}$/;
  if (!str.test(phoneNumber)) {
    showErroTips("请输入正确的手机号码")
    return false;
  } else {
    cbk && cbk();
  }
};

// 判断是否有输入表情符
function isEmojiCharacter(substring, callback) {
  for (var i = 0; i < substring.length; i++) {
    var hs = substring.charCodeAt(i);
    if (0xd800 <= hs && hs <= 0xdbff) {
      if (substring.length > 1) {
        var ls = substring.charCodeAt(i + 1);
        var uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
        if (0x1d000 <= uc && uc <= 0x1f77f) {
          showErroTips("不能输入表情符~");
          return false;
        }
      }
    } else if (substring.length > 1) {
      var ls = substring.charCodeAt(i + 1);
      if (ls == 0x20e3) {
        showErroTips("不能输入表情符~");
        return false;
      }
    } else {
      if (0x2100 <= hs && hs <= 0x27ff) {
        showErroTips("不能输入表情符~");
        return false;
      } else if (0x2B05 <= hs && hs <= 0x2b07) {
        showErroTips("不能输入表情符~");
        return false;
      } else if (0x2934 <= hs && hs <= 0x2935) {
        showErroTips("不能输入表情符~");
        return false;
      } else if (0x3297 <= hs && hs <= 0x3299) {
        showErroTips("不能输入表情符~");
        return false;
      } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 ||
        hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b ||
        hs == 0x2b50) {
        showErroTips("不能输入表情符~");
        return false;
      }
    }
  }
  callback && callback()
}

// 生成二维码
function setQrCode() {
  var user_share_qr_url = system.qrCode;
  // 生成二维码
  $('#qrcode').qrcode({
    render: "canvas",
    width: 100,
    height: 100,
    text: user_share_qr_url
  });
  // 设置二维码图片src
  var qr_src = $('#qrcode canvas')[0].toDataURL("image/jpeg", 1); //原功能
  // var qr_src = "https://activity.infinitus.com.cn/nx_nx_2cc0cdb3-cfc6-24685e0b/static/images/greeting_card_qrcode.png";
  $(".share_srcode").attr("src", qr_src);
}

// 生成分享图
function setShareImg() {
  // 生成分享图
  convert2canvas();
};

// 截图
function convert2canvas() {
  var shareContent = document.querySelector(".img_box");
  var width = shareContent.offsetWidth;
  var height = shareContent.offsetHeight;
  var canvas = document.createElement("canvas");
  var scale = 2;
  canvas.width = width * scale;
  canvas.height = height * scale;
  canvas.getContext("2d").scale(scale, scale);
  var opts = {
    scale: scale,
    canvas: canvas,
    logging: true,
    width: width,
    height: height,
    useCORS: true
  };
  html2canvas(shareContent, opts).then(function (canvas) {
    var context = canvas.getContext('2d');
    context.mozImageSmoothingEnabled = false;
    context.webkitImageSmoothingEnabled = false;
    context.msImageSmoothingEnabled = false;
    context.imageSmoothingEnabled = false;
    var img = canvas.toDataURL("image/jpeg", 0.8);
    // var img = canvas.toDataURL('image/png');
    // var img = Canvas2Image.convertToImage(canvas, canvas.width, canvas.height, "png");
    $(".show_img .img img").attr("src", img);
  });
};